package huiyuan

import (
	"fmt"
	"server/amtf"
	"server/model/system"
	"time"

	"gorm.io/gorm"
)

var A自动挡hook *amtf.S组件自动挡hook

func init() {
	A自动挡hook = &amtf.S组件自动挡hook{}
	A自动挡hook.Ajoin = Ajoin
	amtf.A用户注册后hooks = append(amtf.A用户注册后hooks, 用户注册后hook)
}
func Ajoin(db *gorm.DB) {
	表名 := A组件.A表名
	表全部字段 := 表名 + ".*"

	db.Select(表全部字段, "d1.user_name as 用户名", "d1.nick_name as 昵称", "d1.mobile as 手机").
		Joins(fmt.Sprintf("left join sys_users d1 on d1.id = %s.系统用户_用户id", 表名))
}

func 用户注册后hook(user *system.SysUser) {
	id := user.ID
	model := Amodel
	model.A系统用户_S基础之用户modelID = id
	now := time.Now().AddDate(0, 0, 30)
	model.A到期时间 = &now
	// err := global.A_DB.Create(&model).Error
	// fmt.Printf("err 👉 %+v\n", err)
	A组件.Aservice.A增(&model, id)
}
